import sys
from PyQt5.QtWidgets import QMainWindow,QApplication, QDesktopWidget


class ScreenCenter(QMainWindow):
    def __init__(self, parent=None):
        super(ScreenCenter, self).__init__(parent)
        
        self.resize(400, 300)#设置窗口大小
        self.setWindowTitle("1")#设置窗口标题
        
        self.center()
    def center(self):
        screen = QDesktopWidget().screenGeometry()#获取屏幕尺寸
        size = self.geometry()#获取窗口尺寸
        self.move((screen.width() - size.width()) // 2, (screen.height() - size.height()) // 2)#将窗口移动到屏幕中心

if __name__ == "__main__":
    app = QApplication(sys.argv)
    w = ScreenCenter()
    w.show()
    sys.exit(app.exec_())